// 储存字段名前缀
const namespace = "KEDUODUO_";

export const storage = () => {
	const getKey = (key) => {
		return namespace + key;
	}
	
	const get = (key) => {
		const _key = getKey(key);
		try {
			const value = uni.getStorageSync(_key);
			if (value) return JSON.parse(value);
			return '';
		} catch (e) {
			return '';
		}
	}
	
	const set = (key, val) => {
		const _key = getKey(key);
		const _val = JSON.stringify(val);
		try {
			uni.setStorageSync(_key, _val);
		} catch(e) {
		}
	}

	const remove = (key) => {
		const _key = getKey(key);
		try {
			uni.removeStorageSync(_key);
		} catch(e) {
		}
	}

	return {
		get,
		set,
		remove
	};
}

export default storage;